package com.etoak.controller;

import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.dto.CartDTO;
import com.etoak.service.CartService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {


    @Autowired
    CartService cartService;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @PostMapping
    public ResultVO<Object> add(@Validated @RequestBody CartDTO cartDTO) {
        cartService.add(cartDTO);


        return ResultVO.success();
    }

    @GetMapping("/111")
    public ResultVO<List<CartDTO>> getCartByToken() {
        List<CartDTO> list = cartService.getCartByToken();



        return ResultVO.success(list);
    }

    /**
     * get /cart
     * 查询 当前用户点餐列表
     */
    @GetMapping
    public ResultVO<List<CartDTO>> getList() {
        List<CartDTO> list = cartService.getList();
        return ResultVO.success(list);
    }

    /**
     * 删除对应菜品
     *
     * @param id
     * @return
     */
    @DeleteMapping("/dishes/{id}")
    public ResultVO<Object> deleteDishes(@PathVariable int id) {
        cartService.deleteDishes(id);
        return ResultVO.success();
    }

    @DeleteMapping
    public ResultVO<Object> clearCart() {
        cartService.clearCart();
        return ResultVO.success();
    }
}
